package main

// http请求

import (
	"fmt"
	"io/ioutil"
	"net/http"
)

func main() {
	// http包
	client := http.Client{}
	// func (*http.Client).Get(url string) (resp *http.Response, err error)
	resp, err := client.Get("https://www.baidu.com/")
	if err != nil {
		fmt.Println("client.Get err: ", err)
		return
	}

	// 获取到响应体
	body := resp.Body // 会返回一个接口
	fmt.Println("body: ", body)
	readBody, err := ioutil.ReadAll(body) // 把所有的全部接收
	if err != nil {
		fmt.Println("ioutil.ReadAll err: ", err)
		return
	}
	fmt.Println(string(readBody))

	// 获取响应头相关
	ct := resp.Header.Get("Content-Type")
	fmt.Println(ct)

	// 获取请求相关
	url := resp.Request.URL
	fmt.Println(url)

}
